<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 数据控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\service\TenantEventService;
use think\Request;
use think\Response;

class TenantEventController extends VerifyController
{
    private $tenantEventService;

    public function __construct()
    {
        parent::__construct();
        $this->tenantEventService = TenantEventService::getInstance();
    }

    /**
     * 拉取消息
     * @param Request $request
     * @return Response
     * @throws \Exception
     */
    public function pop(Request $request)
    {
        $resData = $this->tenantEventService->pop($request->getTenantId());
        return json(success_response('', $resData));
    }

    /**
     * 重新发布消息
     * @param Request $request
     * @return Response
     * @throws \Exception
     */
    public function reAdd(Request $request)
    {
        $data = $request->param()['data'];
        $resData = $this->tenantEventService->reAdd($request->getTenantId(), $data['message_id'], $data['message_data']);
        return json(success_response('', $resData));
    }

    /**
     * 标记成功
     *
     * @param Request $request
     * @return Response
     */
    public function ack(Request $request)
    {
        $data = $request->param()['data'];
        $resData = $this->tenantEventService->ack($request->getTenantId(), $data['message_id']);
        return json(success_response('', $resData));
    }

}
